#pragma once
#include "../UIElement.h"
#include <future>

class UISlot
{
public:
	UIElement* uiElement = nullptr;
	float width = 0, height = 0;
};

class UIButton;

class UIScrollPanel : public UIElement
{
public:
	UIScrollPanel();
	UIScrollPanel(float xPos, float yPos);
	UIScrollPanel(float xPos, float yPos, float width, float height);

	// Draws the element on the screen and has to be called between graphics.BeginDraw() and graphics.EndDraw()
	void __stdcall Draw(Graphics* graphics);

	// Fades the elements in over given period of time in miliseconds
	void __stdcall FadeIn(int time);

	// Fades the elements out over given period of time in miliseconds
	void __stdcall FadeOut(int time);

	// Adds element to the next slot
	void AddElement(UIElement* elem);

	// Adds an empty slot
	void AddEmptySlot();

	// Removes element at index from the panel
	void RemoveElement(int index);

	// Removes element from the panel
	void RemoveElement(UIElement* elem);

	// Removes all elements
	void RemoveAllElements();

	// Return the index of the element, -1 if element wasn't found
	int IndexOf(UIElement* elem);

	// Returns number of elements
	int GetElementCount() { return (int)this->slots.size(); }

	// Returns pointer to the element at an index
	UIElement* GetElement(int index)
	{
		if (index < 0 || index > (int)slots.size() - 1) return nullptr;
		return this->slots.at(index)->uiElement;
	}

	UIElement* _get_scrollbar_handle_();

	float MarginsTop = 0.1f;
	float MarginsLeft = 0.1f;
	float SlotWidth = 180, SlotHeight = 30, DistanceBetweenSlots = 0;
	float ScrollbarWidth = 8;
	float ScrollDistance = 16;
	bool Filled = true;
	bool DrawBorder = false;
	float BorderStroke = 1.0f;
	float BorderSize = 4.0f;
	Color BorderColor = Color::LightGray;

	~UIScrollPanel();

private:
	std::vector<UISlot*> slots;
	bool _Should_Draw_Scrollbar = false;

	void SetupScrollbar();
	
	std::unique_ptr<UIButton> Scrollbar;
};
